package nix.bean;

import java.util.HashMap;
import java.util.Map;

import nix.commons.CommonUtils;

import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;

public class TestBean {

	@Test
	public void test1() throws Exception {

		String className = "nix.bean.Person";
		Class clazz = Class.forName(className);
		Object bean = clazz.newInstance();

		BeanUtils.setProperty(bean, "name", "张三");
		BeanUtils.setProperty(bean, "age", 18);
		BeanUtils.setProperty(bean, "gender", "男");

		System.out.println(bean);

		String name = BeanUtils.getProperty(bean, "name");

		System.out.println(name);
	}

	@Test
	public void test2() throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "张三");
		map.put("age", "123");
		map.put("gender", "18");

		Person p = CommonUtils.toBean(map, Person.class);

		System.out.println(p);
	}
}
